/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import utils.Vector3;

/**
 *
 * @author trong_000
 */
public class MathUtil {
     
    /**
     * 
     * @param vector
     * @return Độ dài của vector
     */
    public static double AbsVector3(Vector3 vector) {
        return Math.sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);
    }
    
    /**
     * 
     * @param a
     * @param b
     * @return tích vô hướng của 2 vector a và b
     */
    public static double DotVector3(Vector3 a, Vector3 b) {
        return a.x * b.x + a.y * b.y + a.z * b.z;
    }
    
    /**
     * 
     * @param a
     * @param b
     * @return Góc giữa 2 vector
     */
    public static double Angle2Vector(Vector3 a, Vector3 b) {
        double temp = DotVector3(a, b) / (AbsVector3(a) * AbsVector3(b));
        temp = temp > 1 ? 1 : temp;
        return Math.acos(temp);
    }
    
    /**
     * 
     * @param a
     * @param b
     * @return hiệu của 2 vector
     */
    public static Vector3 SubVector(Vector3 a, Vector3 b) {
        return new Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
    }
    
    /**
     * 
     * @param shoot
     * @param direct
     * @return Tích có hướng của 2 vector
     */
    public static double ScrossProduct(Vector3 shoot, Vector3 direct) {
        double angle = Angle2Vector(shoot, direct);
        double result = AbsVector3(shoot) * AbsVector3(direct) * Math.sin(angle);
        return result;
    }
}
